package com.ruitu.health_1.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.ruitu.arad.Arad;
import com.ruitu.arad.base.base_list.BaseRefreshActivity;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.arad.support.widget.progress.ProgressLayout;
import com.ruitu.health_1.R;
import com.ruitu.health_1.dao.bean.OrderItemList;
import com.ruitu.router_module.Logg;
import com.ruitu.router_module.bean.EventModel;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

public class CommentListActivity extends BaseRefreshActivity {

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_comment_list;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Arad.bus.register(this);
    }

    private ArrayList<OrderItemList> orderList;

    @Override
    protected void initViews() {
        super.initViews();
        setHeadTitle("评论晒单");
        orderList = (ArrayList<OrderItemList>) getIntent().getExtras().get("order");
        Logg.i("OrderList:  "+orderList.toString());
    }

    private DataAdapter adapter;

    @Override
    protected RecyclerView.Adapter initAdapter() {
        adapter = new DataAdapter(this);
        return adapter;
    }

    @Override
    protected LRecyclerView findRecyclerView() {
        return findViewById(R.id.l_recyclerview);
    }

    @Override
    protected void initRecyclerView() {
        super.initRecyclerView();
        adapter.setDataList(orderList);
        setPullRefreshEnabled(false);
        setLoadMoreEnabled(false);
        adapter.setDataList(orderList);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void Comment(EventModel model) {
        if (model.getEventCode() == 2020011300) {
            finish();
        }
    }


    @Override
    protected void reqFirst() {

    }

    @Override
    protected void reqMore() {

    }

    @Override
    protected ProgressLayout findProgressLayout() {
        return null;
    }

    class DataAdapter extends ListBaseAdapter<OrderItemList> {

        public DataAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_comment;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView tv_product_title = holder.getView(R.id.tv_product_title);
            TextView tv_comment = holder.getView(R.id.tv_comment);
            ImageView iv_product_img = holder.getView(R.id.iv_product_img);
            final OrderItemList listBean = mDataList.get(position);
            Glide.with(mContext).load(listBean.getProductPic()).apply(Arad.opts).into(iv_product_img);
            tv_product_title.setText(listBean.getProductName());
            tv_comment.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle = new Bundle();
                    bundle.putString("orderId", listBean.getId());
                    bundle.putString("pic", listBean.getProductPic());
                    startActivity(CommentActivity.class, bundle);
                }
            });
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Arad.bus.unregister(this);
    }
}
